﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


using KingRoad.EPM.PersonnelLogEntity.Model;
using Unis.Framework.Core.Utility;
using KingRoad.EPM.PersonnelLogDAL.PlmDailysupervisionService;


namespace KingRoad.EPM.PersonnelLogBLL.UIRules
{
    /// <summary> 
    /// 客户端业务处理类。 
    /// 文件生成时间 2017/1/12 13:58:02
    /// </summary> 
    public class PlmDailysupervisionUIRule
    {
        private readonly IPlmDailysupervisionService _plmDailysupervisionService;


        public PlmDailysupervisionUIRule() { }

        /// <summary> 
        /// construct function... 
        /// </summary> 
        public PlmDailysupervisionUIRule(IPlmDailysupervisionService plmDailysupervisionService)
        {
            _plmDailysupervisionService = plmDailysupervisionService;
        }

        public bool InsertPlmDailysupervision(PlmDailysupervisionInfo entity)
        {
            var ret = _plmDailysupervisionService.InsertEntity(entity);
            return ret > 0;
        }

        public bool UpdatePlmDailysupervision(PlmDailysupervisionInfo entity)
        {
            var ret = _plmDailysupervisionService.UpdateEntity(entity);
            return ret > 0;
        }

        /// <summary>
        /// 根据总监办标号，和施工日期分组查询信息
        /// </summary>
        /// <param name="directorSection">s总监办标号</param>
        /// <returns></returns>
        public List<PlmDailysupervisionInfo> GetInfoListGroupByDirectorSection(string directorSection)
        {
            var strWhere = " 1=1 ";
            if (!String.IsNullOrEmpty(directorSection))
            {
                strWhere = String.Format(" Clc_DirectorSection='{0}' ", directorSection);
            }
            var ret = _plmDailysupervisionService.GetInfoListGroupByDirectorSection(strWhere);
            return ret;
        }


        /// <summary>
        /// 施工单位人员----根据总监办标号，工作日期,查询
        /// </summary>
        /// <param name="directorSection"></param>
        /// <param name="workDate"></param>
        /// <returns></returns>
        public List<PlmDailysupervisionInfo> GetInfoListByCondition(string directorSection, string workDate)
        {
            return this.GetInfoListByCondition(directorSection, workDate, "");
        }

        /// <summary>
        /// 施工单位人员----根据总监办标号，工作日期，监理标段，查询
        /// </summary>
        /// <param name="directorSection"></param>
        /// <param name="workDate"></param>
        /// <param name="supervisorSection"></param>
        /// <returns></returns>
        public List<PlmDailysupervisionInfo> GetInfoListByCondition(string directorSection,
                                                                    string workDate,
                                                                    string supervisorSection)
        {
            var strWhere = String.Format(" Ds_DirectorSection IN ({0})  ", directorSection);
            if (!String.IsNullOrEmpty(workDate))
            {
                strWhere += String.Format(" AND CONVERT(VARCHAR,Ds_WorkDate,120) LIKE '{0}%'", workDate);
            }
            if (!String.IsNullOrEmpty(supervisorSection))
                strWhere += String.Format(" AND Ds_SupervisorSection='{0}'", supervisorSection);
            //strWhere += " ORDER BY Ds_SupervisorSection DESC ";
            var retList = _plmDailysupervisionService.GetEntityList(strWhere);

            return retList;
        }

        /// <summary>
        /// 根据条件查询信息
        /// </summary>
        /// <param name="numCurrentPage">当前页</param>
        /// <param name="numPerPage">每页数据大小</param>
        /// <param name="orderByField">排序字段名称</param>
        /// <param name="totalRecord">总数据量</param>
        /// <param name="sqlCondition">sql查询条件</param>
        /// <returns></returns>
        public List<PlmDailysupervisionInfo> GetDailysupervisionForPage(int numCurrentPage, int numPerPage, string orderByField, out int totalRecord, string sqlCondition)
        {
            var list = _plmDailysupervisionService.GetEntityListByContionRe(numCurrentPage, numPerPage, orderByField, out totalRecord, sqlCondition);
            return list;
        }
        /// <summary>
        /// 判断是否存在AssisId
        /// </summary>
        /// <param name="assisId"></param>
        /// <returns></returns>
        public bool IsExitAssistId(int assisId)
        {
            var strSql = String.Format(" Assist_ID={0} ", assisId);
            var list = _plmDailysupervisionService.GetEntityList(strSql);
            return list.Any();
        }

        public List<TK> GetEntityListByContionRe<TK>(int numCurrentPage, int numPerPage, string orderByField, List<TK> list)
            where TK : new()
        {
            var ret = _plmDailysupervisionService.GetEntityListByContionRe<TK>(numCurrentPage, numPerPage, orderByField, list);
            return ret;
        }

        public int DeleteObjetById(string id)
        {
            return _plmDailysupervisionService.DeleteEntityByStringID(id);
        }
    }
}
